﻿Public Class DreporteGerencial
    Public Shared Function ObtenerDatosReporteGerencial(ByVal descEmpresa As String, ByVal FechaInicio As String, ByVal FechaFinal As String, ByVal idProyecto As Int32, ByVal idEtapa As Int32) As List(Of EReporteGerencial)
        Dim reportegerencial As List(Of EReporteGerencial) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_EmailGerencial_TendenciaSeisMeses", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@fechaIni", SqlDbType.VarChar, 10).Value = FechaInicio
                cmd.Parameters.Add("@fechaFin", SqlDbType.VarChar, 10).Value = FechaFinal
                cmd.Parameters.Add("@idProyecto", SqlDbType.Int).Value = idProyecto
                cmd.Parameters.Add("@idEtapa", SqlDbType.Int).Value = idEtapa
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            reportegerencial = New List(Of EReporteGerencial)
                            Dim unidad As EReporteGerencial = Nothing
                            Do While dr.Read
                                unidad = New EReporteGerencial( _
                                    dr.GetString(dr.GetOrdinal("Proyecto")), _
                                    dr.GetInt32(dr.GetOrdinal("Tpogestion")), _
                                    dr.GetInt32(dr.GetOrdinal("Mes01")), _
                                    dr.GetInt32(dr.GetOrdinal("Mes02")), _
                                    dr.GetInt32(dr.GetOrdinal("Mes03")), _
                                    dr.GetInt32(dr.GetOrdinal("Mes04")), _
                                    dr.GetInt32(dr.GetOrdinal("Mes05")), _
                                    dr.GetInt32(dr.GetOrdinal("Mes06")))
                                reportegerencial.Add(unidad)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return reportegerencial
    End Function
End Class
